package com.example.day2_popupwindow;

import androidx.appcompat.app.AppCompatActivity;

import android.app.ActionBar;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.PopupWindow;

public class Main2Activity extends AppCompatActivity {
    ImageView imageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        imageView = findViewById(R.id.iv);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showwindow();
            }
        });
    }

    private void showwindow() {
        PopupWindow popupWindow = new PopupWindow(this);
        View view1 = LayoutInflater.from(this).inflate(R.layout.popup_two, null);
        popupWindow.setContentView(view1);
        popupWindow.setWidth(300);
        popupWindow.setHeight(ActionBar.LayoutParams.WRAP_CONTENT);
        popupWindow.setOutsideTouchable(true);
        //显示不一样了
        popupWindow.showAsDropDown(imageView,-400,200);

    }
}
